import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-11-04
 * Time: 20:52
 */
public class test_2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            long[] arr = new long[n];
            long[] dp = new long[n + 1];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }
            long max = Long.MIN_VALUE;
            for (int i = 1; i <= n; i++) {
                if (dp[i - 1] > 0) {
                    dp[i] +=dp[i - 1];
                }
                dp[i] += arr[i - 1];
                max = Math.max(max, dp[i]);
            }

            System.out.println(max);
        }
    }
}
